package LeetCode.leetcode1047;

import java.util.Stack;

public class Review1 {
    public String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char t = s.charAt(i);
            if (!stack.isEmpty() && stack.peek() == t){
                stack.pop();
            }else {
                stack.push(t);
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!stack.isEmpty()){
            sb.append(stack.pop());
        }
        return sb.reverse().toString();
    }
}
